package com.groupname.dangerousdelves;

import android.os.Bundle;
import java.io.IOException;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer.OnCompletionListener;
import android.content.Context;
import android.media.MediaPlayer;
import android.content.Intent;
import android.os.IBinder;
import android.app.Service;

// -------------------------------------------------------------------------
/**
 *  This class is responsible for loading and playing music.
 *
 *  NOTE: There is a glitch with the AVD where the snapshots cause it to not
 *  play music. In order to hear anything you must create a new AVD every time
 *  you run this game.
 *
 *  @author Chris Fieldman
 *  @version 2012.11.18
 */
public class SplashMusic
    extends Service
{
    //~-------------------------------------------------------------------------
    // Member Variables
    private MediaPlayer mediaPlayer;
    public static boolean isRunning;

    //~-------------------------------------------------------------------------
    // Methods
    @Override
    public void onCreate()
    {
        super.onCreate();

        this.mediaPlayer = MediaPlayer.create(this,
            R.raw.toglorymono16);

        this.mediaPlayer.setLooping(true);

        this.mediaPlayer.setVolume(100, 100);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    {
        try
        {
            isRunning = true;
            this.mediaPlayer.start();
        }
        catch(Exception e)
        {
            this.mediaPlayer.stop();
            isRunning = false;
        }

        return 1;
    }

    @Override
    public void onDestroy()
    {
        this.mediaPlayer.stop();
        this.mediaPlayer.release();
    }

    @Override
    public void onLowMemory()
    {
        this.mediaPlayer.stop();
    }

    @Override
    public IBinder onBind(Intent intent)
    {
        // TODO Auto-generated method stub
        return null;
    }
}
